﻿/************************************************************************

 This file is part of EscapeFromPrisonPlanet.

 EscapeFromPrisonPlanet is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 EscapeFromPrisonPlanet is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

// All code (c)2012 Scott Bevin. all rights reserved

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace LudumDare25Project.Objects
{
    internal class Flame
    {
        public Vector2 Offset = Vector2.Zero;

        private Vector2[] DrawOffsets = new Vector2[3];
        private Texture2D[] Textures = new Texture2D[3];

        public float BaseScale = 1.0f;
        private float[] Timers = new float[3];

        public Flame(ContentManager content, Vector2 offset, float scale)
        {
            BaseScale = scale;
            Offset = offset;

            Textures[0] = content.Load<Texture2D>("Img/FlameRed");
            Textures[1] = content.Load<Texture2D>("Img/FlameOrange");
            Textures[2] = content.Load<Texture2D>("Img/FlameYellow");

            for (int i = 0; i < 3; ++i)
            {
                Timers[i] = 0.0f;

                DrawOffsets[i] = new Vector2(
                    (float)Textures[i].Width * 0.75f,
                    (float)Textures[i].Height * 0.5f);
            }
        }

        public void Update(float dt)
        {
            for (int i = 0; i < 3; ++i)
            {
                Timers[i] += dt * 10.0f * ((float)(i + 1));
            }
        }

        public void Draw(SpriteBatch sprites, Vector2 Position, float rotation)
        {
            Vector2 offset = Offset;

            offset.X += (float)(Math.Cos(rotation - MathHelper.PiOver2) * 2f);
            offset.Y += (float)(Math.Sin(rotation - MathHelper.PiOver2) * 2f);

            Position += offset;

            for (int i = 0; i < 3; ++i)
            {
                sprites.Draw(
                    Textures[i],
                    Position,
                    null,
                    Color.White,
                    rotation,
                    DrawOffsets[i],
                    BaseScale + ((float)Math.Sin(Timers[i]) * 0.3f),
                    SpriteEffects.None,
                    0.0f);
            }
        }
    }
}